package common 
{
	import common.ITest;
	import flash.utils.getQualifiedClassName;
	/**
	 * ...
	 * @author Luke Van In
	 */
	public class CompositeTest implements ICompositeTest 
	{
		
		private var _description:String;
		
		private var _tests:Vector.<ITest>;
		
		
		
		public function CompositeTest(description:String) 
		{
			this._description = description;
			
			this._tests = new Vector.<ITest>();
		}
		
		
		
		/**
		 * 
		 * @param	test
		 * @throws	Error	Test must not be null
		 */
		public function addTest(test:ITest):void 
		{
			if (test == null)
				throw new Error("Cannot add a null test");
				
			this._tests.push(test);
		}

		
		
		/**
		 * Runs all sub-tests
		 * 
		 * @return	Returns true if all sub-tests pass, or false otherwise
		 */
		public function run():ITestResult
		{
			var testResults:ICompositeTestResult = new CompositeTestResult(this._description);
			
			for (var i:int = 0; i < this._tests.length; i++)
			{
				var testResult:ITestResult = this.runTest(this._tests[i]);
				
				testResults.addTestResult(testResult);
			}
				
			return testResults
		}
		
		
		
		
		/**
		 * Runs a test
		 * 
		 * @param	test
		 * @return	Returns the result of the test
		 */
		private function runTest(test:ITest):ITestResult
		{
			var result:ITestResult = test.run();
			
			return result;
		}
	
		
		
		

		
		
		
	}

}